#pragma once
#include "hittable.h"
class hittable_list :public hittable
{
public:
	hittable_list() {}
	hittable_list(hittable** l, int n) : list(l), list_size(n) {}
	virtual bool hit(const ray& r, float tmin, float tmax, hit_record& rec)const;
	hittable** list;
	int list_size;
};

bool hittable_list::hit(const ray& r, float tmin, float tmax, hit_record& rec) const
{
	hit_record temp_rec;
	bool bRet = false;
	double closet_so_far = tmax;

	for (int i = 0; i < list_size; ++i)
	{
		bool bHit = list[i]->hit(r, tmin, closet_so_far, temp_rec);
		if (bHit)
		{
			bRet = true;
			rec = temp_rec;
			closet_so_far = temp_rec.t;
		}
	}

	return bRet;
}